/***********************************************************************
    filename:   CEGUIExceptions.cpp
    created:    20/2/2004
    author:     Paul D Turner, Frederico Jeronimo (fjeronimo)

    purpose:    Implements the exception classes used within the system
*************************************************************************/

#include "hgeExceptions.h"
#include "hgeLogger.h"
#include "hgePropertyHelper.h"
#include <iostream>

//----------------------------------------------------------------------------//
Exception::Exception(const String& message, const String& name,
                     const String& filename, int line) :
    d_message(message),
    d_filename(filename),
    d_name(name),
    d_line(line),
    d_what(name + " in file " + filename  +
           "(" + PropertyHelper::intToString(line) + ") : " + message)
{
    // Log exception or send it to error stream (if logger not available)
    hgeLogger* const logger = hgeLogger::getSingletonPtr();
    if (logger)
        logger->logEvent(d_what, Errors);
    else
        std::cerr << what() << std::endl;
}

//----------------------------------------------------------------------------//
Exception::~Exception(void) throw()
{
}

//----------------------------------------------------------------------------//
const char* Exception::what() const throw()
{
    return d_what.c_str();
}
